﻿
CREATE PROCEDURE [dbo].[OPM_ReturnOrderHeader_Insert]
(
	--@ReturnOrderNumber  nvarchar(50),
	--@ReturnOrderStatusId  int,
	@WangWangId  nvarchar(50),
	@CustomerName  nvarchar(50),
	@CustomerCellphone  nvarchar(50),
	@CustomerAddress nvarchar(500),
	@CreatedBy int,
	@Id int OUTPUT
)

AS


INSERT INTO dbo.[OPM_ReturnOrderHeader]
(
	--[ReturnOrderNumber],
	[ReturnOrderStatusId],
	[WangWangId],
	[CustomerName],
	[CustomerCellphone],
	[CustomerAddress],
	[CreatedBy],
	[UpdatedBy],
	[CreatedOn],
	[UpdatedOn],
    [ROWGUID]
)
VALUES
(
	--@ReturnOrderNumber,
	1,
	@WangWangId,
	@CustomerName,
	@CustomerCellphone,
	@CustomerAddress,
	@CreatedBy,
	@CreatedBy,
	getdate(),
	getdate(),
    newid()
)

SET @Id = SCOPE_IDENTITY();

UPDATE dbo.OPM_ReturnOrderHeader
SET ReturnOrderNumber = 'RS' + STR(@Id)
WHERE Id = @Id